TESTS_DIR := $(top_srcdir)tests/
TESTS_OUT := $(top_builddir)tests/

WR_CXX := WRAPPER_INCLUDEDIR=-I$(top_srcdir)include WRAPPER_LIBDIR=-L$(top_builddir)src $(WRAPPER)

LDFLAGS := $(LDFLAGS-$(LIBNAME).so) $(call link.asneeded,-lgcc_s)

TESTS_SRCS-y := $(wildcard *test.cpp)
UTILITY_SRCS := testframework.cpp

TESTS_OMIT-$(UCLIBCXX_HAS_WCHAR) := wchartest.cpp
TESTS_OMIT-$(UCLIBCXX_EXCEPTION_SUPPORT) := excepttest.cpp

TESTS_SRCS-y := $(filter-out $(TESTS_OMIT-),$(TESTS_SRCS-y))

EXOBJS            := $(patsubst %.cpp,%.o, $(TESTS_SRCS-y))
UTILITY_OBJS      := $(patsubst %.cpp,%.o, $(UTILITY_SRCS))
ALLBIN            := $(patsubst %.cpp,%, $(TESTS_SRCS-y))
HOST_OBJS         := $(patsubst %.cpp,%-old.o, $(TESTS_SRCS-y))
HOST_UTILITY_OBJS := $(patsubst %.cpp,%-old.o, $(UTILITY_SRCS))
HOST_BIN          := $(patsubst %.cpp,%-old, $(TESTS_SRCS-y))

all: $(ALLBIN) $(if $(DODEBUG),$(HOST_BIN))
include $(TESTS_DIR)testoutput/Makefile.in

DEPS-valarraytest := -lm

$(EXOBJS) $(UTILITY_OBJS): $(WRAPPER)
%.o: %.cpp ; $(compile.oxx)
%: %.o ; $(compile.uxx)

%-old.o: %.cpp ; $(hcompile.oxx)
%-old: %-old.o ; $(hcompile.uxx)

$(ALLBIN): % : %.o $(UTILITY_OBJS)
$(HOST_BIN): % : %.o $(HOST_UTILITY_OBJS)

CLEAN_tests:
	$(do_rm) $(addprefix $(TESTS_OUT),$(ALLBIN) $(HOST_BIN) *.o core)

clean: CLEAN_testoutput CLEAN_tests
